<?php
class LoginController {
	function doLoginControll() {
		$loginHandler = new LoginHandler();
		$loginView = new LoginView();

		$logoutBox = $loginView -> createLoggedInBox();
		$loginBox = $loginView -> createLoginBox();

		if ($loginHandler -> isLoggedIn()) {
			// If user is logged in, add 'log out'-box
			$content = $logoutBox;
			// If user tried to logout
			if ($loginView -> triedToLogout()) {
				// Unset login
				$loginView -> unsetOKLogin();
				// Log out
				$loginHandler -> doLogout();
				$content = $loginBox;
				return $content;
			}
		} else {
			// If user is logged out, add 'log in'-box
			$loginBox = $loginView -> createLoginBox();
			$content = $loginBox;

			// If user tried to Login
			if ($loginView -> triedToLogin()) {
				// Get input name and password
				$username = $loginView -> getUserName();
				$password = $loginView -> getPassword();
				// Login
				if ($loginHandler -> doLogin($username, $password)) {
					// Set ok login
					$loginView -> setOKLogin($username, $password);
					// If login succeeded - show logoutbox
					$content = $logoutBox;
					return $content;
				} else {
					$content = $loginBox;
					return $content;
				}
			}
		}
		return $content;
	}

	function doLogoutControll() {

	}

}
?>